import { MessageBox, Notification, Loading } from "element-ui"
import Message from "@/plugins/reset-message.js"

let loadingInstance

export default {
  // 消息提示
  msg(content = "提示信息") {
    Message.info(content)
  },
  // 错误消息
  msgError(content = "错误提示") {
    Message.error(content)
  },
  // 成功消息
  msgSuccess(content = "成功提示") {
    Message.success(content)
  },
  // 警告消息
  msgWarning(content = "警告提示") {
    Message.warning(content)
  },
  // 弹出提示
  alert(content = "提示信息") {
    return MessageBox.alert(content, "系统提示")
  },
  // 错误提示
  alertError(content = "错误提示") {
    return MessageBox.alert(content, "系统提示", { type: "error"})
  },
  // 成功提示
  alertSuccess(content = "成功提示") {
    return MessageBox.alert(content, "系统提示", { type: "success" })
  },
  // 警告提示
  alertWarning(content = "警告提示") {
    return MessageBox.alert(content, "系统提示", { type: "warning" })
  },
  // 通知提示
  notify(content = "提示信息") {
    Notification.info(content)
  },
  // 错误通知
  notifyError(content = "错误提示") {
    Notification.error(content)
  },
  // 成功通知
  notifySuccess(content = "成功提示") {
    Notification.success(content)
  },
  // 警告通知
  notifyWarning(content = "警告提示") {
    Notification.warning(content)
  },
  // 确认窗体
  confirm(content = "确认提示", options) {
    const title = options?.title || "系统提示"
    const defaultOptions = {
      confirmButtonText: "确定",
      cancelButtonText: "取消",
      type: "warning"
    }
    options = Object.assign(defaultOptions, options)
    return MessageBox.confirm(content, title, options)
  },
  // 提交内容
  prompt(content = "确认提示", options) {
    const title = options?.title || "系统提示"
    const defaultOptions = {
      confirmButtonText: "确定",
      cancelButtonText: "取消",
      closeOnClickModal: false,
      type: "warning"
    }
    options = Object.assign(defaultOptions, options)
    return MessageBox.prompt(content, title, options)
  },
  // 打开遮罩层
  loading(content = "正在加载") {
    loadingInstance = Loading.service({
      lock: true,
      text: content,
      spinner: "el-icon-loading",
      background: "rgba(0, 0, 0, 0.7)"
    })
  },
  // 关闭遮罩层
  closeLoading() {
    loadingInstance.close()
  }
}
